using UnityEngine;
using System.Collections;

public class SceneLoadManager : MonoBehaviour{
	
	public enum LoadState{
		LOADED,
		LOADING,
	};	
		
	private LoadState mCurrLoadState = LoadState.LOADED;
	
	/// <summary>
	/// Gets the state of the scene
	/// </summary>
	/// <value>
	/// The state of the curr load.
	/// </value>
	public LoadState CurrLoadState{
		get{return mCurrLoadState;}
	}
	
	private string mCurrSceneName = "Start";
	
	/// <summary>
	/// Gets the name of the curr scene.
	/// </summary>
	/// <value>
	/// The name of the curr scene.
	/// </value>
	public string CurrSceneName{
		get{return mCurrSceneName;}
	}
	
	/// <summary>
	/// Changes the scene.
	/// </summary>
	/// <param name='levelName'>
	/// Level name in folder Assets/Scene/
	/// </param>
	public void ChangeScene(string levelName){
		StartCoroutine( DoChangeScene(levelName) );
	}
	
	private IEnumerator DoChangeScene(string levelName){
		
		mCurrLoadState = LoadState.LOADING;
		
		AsyncOperation ao = Application.LoadLevelAsync(levelName);
		while (!ao.isDone){
			yield return null;
		}
				
		Resources.UnloadUnusedAssets();
		
		mCurrSceneName = levelName;
		mCurrLoadState = LoadState.LOADING;
				
		//tzz added for scene fade 
		SceneFadeInOut.Instance.FadeInScene(3);
	}
}
